Page({
  data: {
    musicList: [
      {
        title: '跑步',
        src: '/music/run.mp3'
      },
      {
        title: '跳绳',
        src: '/music/skipping.mp3'
      },
      {
        title: '哑铃',
        src: '/music/dumbbell.mp3'
      }
    ],
    info: 'JOIN US! 健身俱乐部 COME ON! 我能行',
    count: {
      '跑步': "8.5 km",
      '跳绳': "5 次",  
      '哑铃': "12 次",
    },
    imgList: [
      '/images/img1.jpg',
      '/images/img2.jpg', 
      '/images/img3.jpg'
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 1000,
    greeting: "早上好！",
    invitationImages: [
      "/images/img4.jpg",
      "https://example.com/image2.jpg",
      "https://example.com/image3.jpg"
    ],
    habits: [
      { name: '早起', checked: false },
      { name: '锻炼', checked: false },
      { name: '阅读', checked: false },
    ],
    ranking: [
      { name: '张三', points: 100 },
      { name: '李四', points: 90 },
      { name: '王五', points: 80 },
    ],
  },

  inputHandler(e) {
    console.log(e.detail.value)
  },

  clickMe() {
    this.setData({ msg: "Hello World" });
  },

  clickView1() {
    console.log("您点击了view1");
    var price11 = this.data.price1;
    this.setData({
      price1: price11 + 10,
    });
  },

  clickView2() {
    console.log("您点击了view2");
    var price22 = this.data.price2;
    this.setData({
      price2: price22 + 10,
    });
  },

  clickView3() {
    console.log("您点击了view3");
    var price33 = this.data.price3;
    this.setData({
      price3: price33 + 10,
    });
  },

  methods: {
    incrementCounter(e) {
      const type = e.currentTarget.dataset.type;
      const music = this.data.musicList.find(item => item.title === type);
      if (music) {
        wx.createInnerAudioContext().src = music.src;
        wx.play();
      }
    },
    goBack() {
      wx.navigateTo({
        url: '/pages/index/index'
      });
    }
  },

  incrementCounter(event) {
    const type = event.currentTarget.dataset.type; // 获取当前点击项的数据类型
    let count = this.data.count;
    count[type]++; // 根据数据类型递增计数器
    this.setData({ count });
  },

  jumptoactivity() {
    wx.navigateTo({
      url: '/pages/run/run'
    });
  },

  onChange(e) {
    const index = e.detail.value.index;
    const habit = this.data.habits[index];
    habit.checked = !habit.checked;
    this.updateRanking();
  },

  updateRanking() {
    const newRanking = [];
    for (let i = 0; i < this.data.habits.length; i++) {
      const habit = this.data.habits[i];
      if (habit.checked) {
        newRanking.push({ name: habit.name, points: 5 });
      }
    }
    this.setData({ ranking: newRanking });
  },

  goBack() {
    wx.navigateTo({
      url: '/pages/index/index'
    });
  }
});
